﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Model;

namespace LaKuaShop_TestDemo.Page
{
    /// <summary>
    /// LookOrderPage.xaml 的交互逻辑
    /// </summary>
    public partial class LookOrderPage : System.Windows.Controls.Page
    {
        public LookOrderPage()
        {
            InitializeComponent();
            InitOrderList();
        }
        private void InitOrderList()
        {
            List<Orderlist> ex = new List<Orderlist>();
            BLL.Order Ord = new BLL.Order();
            BLL.Product Pro = new BLL.Product();
            List<OrderInfo> orderInfolst = Ord.GetOrderInfo(Common.User.account);
            foreach (OrderInfo orderInfo in orderInfolst)
            {
                for (int i = 0; i < orderInfo.PidList.Count; i++)
                {
                    ProductInfo productInfo = Pro.ShowProductInfo(orderInfo.PidList[i]);
                    byte[] img = Pro.ShowProductImg(orderInfo.PidList[i]);
                    BitmapImage bmp = new BitmapImage();
                    if (img == null)
                    {
                        bmp = new BitmapImage(new Uri("/newlogo.png", UriKind.Relative));
                    }
                    else
                    {
                        MemoryStream stream = new MemoryStream(img);
                        bmp.BeginInit();//初始化
                        bmp.StreamSource = stream;//设置源
                        bmp.EndInit();//初始化结束
                    }
                    string pricestr = "￥" + string.Format("{0:n2}", productInfo.Pprice*orderInfo.Onum[i]);
                    string numstr = "x " + orderInfo.Onum[i].ToString();
                    ex.Add(new Orderlist(bmp, pricestr, productInfo.Pname, numstr));
                    LookOrderList.ItemsSource = ex;
                }
            }

        }
        class Orderlist
        {
            public BitmapImage pic { get; set; }
            public string price { get; set; }
            public string name { get; set; }
            public string num { get; set; }
            public Orderlist(BitmapImage pic, string price, string name, string num)
            {
                this.pic = pic;
                this.price = price;
                this.name = name;
                this.num = num;
            }

        }
    }
}
